package com.cdm.beans;

import net.sf.frails.bean.annotations.DefMbean;
import net.sf.frails.bean.annotations.PreRender;
import net.sf.frails.bean.annotations.Prop;

import com.cdm.persistence.EntityManagerHelper;
import com.cdm.persistence.User;

@DefMbean
public class UserCreateBean {

	@Prop
	User user;

	@Prop
	boolean create = true;

	@PreRender(failOutcome = "lisUser")
	public boolean init() {
		if (user == null) {
			user = new User();
		} else if (create) {
			user = new User();
		}

		return true;
	}

	public String saveUser() {
		EntityManagerHelper.beginTransaction();
		EntityManagerHelper.getEntityManager().persist(user);
		EntityManagerHelper.commit();
		return "createUser";
	}
}
